<?php
	namespace Admin\Controller;
	use Think\Controller;
	class HuoController extends Controller {

		public function index()
		{
			//查询       
         if ($_GET['sub']=="查询") {
                $key=$_GET['keywords'];
         		// $type=$_GET['search'];
         		// $this->search=$type;
            $wheres['sname']=array('like',"%$key%");
            $wheres['stype']=$type;
            $wheres=array_filter($wheres); 
         }else{
            $wheres='';
         }

		$db=M("Huoshen"); // 实例化Plan对象
		$count      = $db->where($wheres)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(15)
		$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$Uarr = $db->where($wheres)->order('createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('Garr',$Uarr);// 赋值数据集    	   
		$this->assign('page',$show);// 赋值分页输出
		$this->display(); // 输出模板
		}

		public function shen($id)
		{
			$db=M("Huoshen"); 
			if (IS_POST) {
				 
			$sid=I("post.usd");
			$data['yijian']=I("post.yuan");
			$data['status']=I("post.shen");
			array_filter($data);
			$list=$db->where('sid='.$sid)->save($data);
			if ($list) {
				    
				    echo "<script>
				            alert('成功');
				            location.href='/Admin/Gongshi';//客户端跳转
				          </script>";
			}else{

				    echo "<script>
				            alert('失败');
				          </script>";
			}
				   
			}else{
			
			$Uarr=$db->where('sid='.$id)->find();
			$this->Uarr=$Uarr;
			$photo=M("Sphotos");
			$Parr=$photo->where('sid='.$id)->select();
			$this->Parr=$Parr;
			$this->display();
		  }
		}
		public function up()
		{
			$wheres['sid']=I("post.sid");
			$data['stus']=I("post.sta");
			if (IS_POST) {
				$db=M("Huoshen"); 
				$list=$db->where($wheres)->save($data);
				if ($list) {
					echo "修改成功";
				}else{
					echo "修改失败";
				}
			}
		}

   // 删除
    public function delete($sid) {
        if (!empty($sid)) {
            $Form = M("Huoshen");
            $result = $Form->delete($sid);
            if (false !== $result) {
                echo '删除成功！';
            } else {
                echo '删除出错！';
            }
        } else {
            $this->error('ID错误！');
        }
    }
	}